package com.xzx.spark.core.transform

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 *
 *
 * @author xinzhixuan
 * @version 1.0
 * @date 2021-06-26 8:39 下午
 */
object Spark022_KeyValue_Join {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local[*]").setAppName("Spark022_KeyValue_Join")
    val sc = new SparkContext(conf)
    val rdd: RDD[(Int, String)] = sc.makeRDD(Array((1, "a"), (2, "b"), (3, "c"), (5, "d"), (3, "f")))
    val rdd1: RDD[(Int, Int)] = sc.makeRDD(Array((1, 4), (2, 5), (3, 6), (4, 7)))
    rdd.join(rdd1).collect().foreach(println)
    println("=======================================")
    rdd.leftOuterJoin(rdd1).collect().foreach(println)
    println("=======================================")
    rdd.cogroup(rdd1).collect().foreach(println)

    sc.stop()
  }
}
